//
//  PartyCategoryViewController.m
//  UESTCPioneer
//
//  Created by Apple on 14-7-1.
//  Copyright (c) 2014年 Sway. All rights reserved.
//

#import "PartyCategoryViewController.h"
#import "PartyActivityViewController.h"
@interface PartyCategoryViewController ()
{
    selectCategoryBlock _selectCategoryBlock;
}
@property (nonatomic,strong) NSMutableArray * contentArray;
@property (nonatomic,strong) PartyActivityViewController * sourceController;
@end

@implementation PartyCategoryViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(id)initWithArray:(NSArray *)array{
//    NSLog(@"+++++++++++++++++++++++++");
    if (self) {
        self.contentArray = [NSMutableArray arrayWithArray:array];
    }
    [self.tabelView reloadData];
    return self;
}

-(id)initWithArray:(NSArray *)array block:(selectCategoryBlock)block{
//    NSLog(@"-------------------------");
    if (self) {
        self.contentArray = [NSMutableArray arrayWithArray:array];
    }
    [self.tabelView reloadData];
    
    _selectCategoryBlock = block;
    
    return self;

}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.tabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame
                                                                   .size.height)];
    [self.tabelView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addSubview:self.tabelView];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.tabelView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.tabelView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.tabelView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.tabelView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0]];

    self.tabelView.dataSource = self;
    self.tabelView.delegate = self;
//    NSLog(@"self.tabelView = %@",self.tabelView);
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    

    
//    [self getCollege];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.contentArray.count;
}

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier = @"colleage";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier ];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = self.contentArray[indexPath.row][@"partyName"];
    return  cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    _selectCategoryBlock(self.contentArray[indexPath.row]);
    [self.leveyTabBarController.navigationController popToRootViewControllerAnimated:YES];
//    self.sourceController. 
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    self.sourceController = segue.sourceViewController;
}
@end
